#include "Timer.h"

Timer::Timer()
{
	m_currentTime = 0;
	m_currentTimeMS = 0;
	m_ticksPreviousFrame = (unsigned int)GetTickCount();
	m_dt = 0;
	m_dtMS = 0;
}

void Timer::UpdateTime()
{
	MutexLocker ml(&m_mutex);
	unsigned int ticksCurrentFrame = (unsigned int)GetTickCount();
	unsigned int diff = ticksCurrentFrame - m_ticksPreviousFrame;

	m_dtMS = (unsigned int)diff;
	m_dt = (float)diff * 0.001f;

	m_ticksPreviousFrame = ticksCurrentFrame;

	m_currentTime += m_dt;
	m_currentTimeMS += m_dtMS;

	 //       static DWORD dwTimeStart = 0;
  //      DWORD dwTimeCur = GetTickCount();
  //      if( dwTimeStart == 0 )
  //          dwTimeStart = dwTimeCur;

		//static float curTime = 0;
  //      curTime = ( dwTimeCur - dwTimeStart ) / 1000.0f;

}

void Timer::SetTimeMS(unsigned int ms)
{
	m_currentTimeMS = ms;
}

unsigned int Timer::GetTimeMS() const
{
	return m_currentTimeMS;
}

unsigned int Timer::GetDtMS() const
{
	return m_dtMS;
}

float Timer::GetTime()
{
	return m_currentTime;
}

float Timer::GetDt()
{
	return m_dt;
}